package net.dgg.rz.evaluating.controller;


import net.dgg.framework.tac.utils.DggValidateUtil;
import net.dgg.framework.tac.utils.bean.DggRestResponse;
import net.dgg.framework.tac.utils.web.commmon.DggBaseController;
import net.dgg.rz.common.constant.ScProductConstant;
import net.dgg.rz.common.utils.DataTableResponse;
import net.dgg.rz.common.utils.evaluatingExcel.ReadExcel;
import net.dgg.rz.evaluating.entity.*;
import net.dgg.rz.evaluating.entity.dto.*;
import net.dgg.rz.evaluating.service.EvaluatingService;
import net.dgg.rz.production.exception.ProductOrderExcption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileInputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zyou on 2019-05-22 .
 **/
@Controller
@RequestMapping("/rzsc/evaluating")
public class EvaluatingController extends DggBaseController {

    @Autowired
    private EvaluatingService evaluatingService;
    /**
     * 评测试题
     */
    @RequestMapping(value = "/test_paper")
    public String testPaper() {
        return "rzsc/evaluating/test_paper";
    }
    /**
     * 基础渠道
     */
    @RequestMapping(value = "/base_channel")
    public String baseChannel() {
        return "rzsc/evaluating/base_channel";
    }
    /**
     * 基础题目
     */
    @RequestMapping(value = "/base_subject")
    public String baseSubject() {
        return "rzsc/evaluating/base_subject";
    }
    /**
     * 基础选项
     */
    @RequestMapping(value = "/base_options")
    public String baseOptions() {
        return "rzsc/evaluating/base_options";
    }
    /**
     * 评估结果
     */
    @RequestMapping(value = "/assessment_results")
    public String assessmentResults() {
        return "rzsc/evaluating/assessment_results";
    }
    /**
     * 评估结果等级
     */
    @RequestMapping(value = "/assessment_level")
    public String assessmentLevel() {
        return "rzsc/evaluating/assessment_level";
    }
    /**
     * 导入试题
     */
    @RequestMapping(value = "/add_paper_excel")
    public String addPaperExcel() {
        return "rzsc/evaluating/add_paper_excel";
    }
    /**
     * 新增基础渠道
     */
    @RequestMapping(value = "/add_channel")
    public String addChannel(Long id, Model model) {
        if(id != null){
            EvaluatingBaseChannel evaluatingBaseChannel = evaluatingService.getBaseChannelById(id);
            model.addAttribute("evaluatingBaseChannel",evaluatingBaseChannel);
        }
        return "rzsc/evaluating/add_channel";
    }
    /**
     * 新增基础选项
     */
    @RequestMapping(value = "/add_options")
    public String addOptions(Long id, Model model) {
        if(id != null){
            EvaluatingBasicOptions evaluatingBasicOptions = evaluatingService.getBaseOptionsById(id);
            model.addAttribute("evaluatingBasicOptions",evaluatingBasicOptions);
        }
        return "rzsc/evaluating/add_options";
    }

    /**
     * 新增基础题目
     */
    @RequestMapping(value = "/add_subject")
    public String addSubject(Long id, Model model) {
        if(id != null){
            EvaluatingPaperSubject evaluatingPaperSubject = evaluatingService.getBaseSubjectById(id);
            model.addAttribute("evaluatingPaperSubject",evaluatingPaperSubject);
        }
        List<EvaluatingTestPaper> paperList = evaluatingService.paperList();
        model.addAttribute("paperList",paperList);
        return "rzsc/evaluating/add_subject";
    }

    /**
     * 删除题目
     * @return
     */
    @RequestMapping(value = "/delete_subject")
    @ResponseBody
    public DggRestResponse deleteSubject(Long id) {
        try {
            DggValidateUtil.notNull(id,ProductOrderExcption.class,"id为空");
            EvaluatingPaperSubject evaluatingPaperSubject = new EvaluatingPaperSubject();
            evaluatingPaperSubject.setId(id);
            evaluatingPaperSubject.setFlag(1);
            evaluatingService.saveSubject(evaluatingPaperSubject);
            return this.getSuccessResponse("删除成功");
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     * 新增评估结果
     */
    @RequestMapping(value = "/add_assessment")
    public String addAssessment(Long id, Model model) {
        List<EvaluatingTestPaper> evaluatingTestPapers = evaluatingService.paperList();
        model.addAttribute("evaluatingTestPapers",evaluatingTestPapers);
        if(id != null){
            EvaluatingResults evaluatingResults = evaluatingService.getAssessmentResultsById(id);
            model.addAttribute("evaluatingResults",evaluatingResults);
        }
        return "rzsc/evaluating/add_assessment";
    }
    /**
     * 新增试题
     */
    @RequestMapping(value = "/add_paper")
    public String addPaper(Long id, Model model) {
        if(id != null){
            EvaluatingTestPaper evaluatingTestPaper = evaluatingService.getPaperById(id);
            model.addAttribute("evaluatingTestPaper",evaluatingTestPaper);
        }
        return "rzsc/evaluating/add_paper";
    }

    /**
     * 渠道列表
     * @param params
     * @return
     */
    @RequestMapping(value = "/channel_list")
    @ResponseBody
    public DggRestResponse channelList(@RequestParam Map params) {
        try {
            List<EvaluatingBaseChannel> evaluatingBaseChannels = evaluatingService.channelListWithPage(params);
            return new DataTableResponse().data(params,evaluatingBaseChannels);
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     * 题目列表
     * @param params
     * @return
     */
    @RequestMapping(value = "/subject_list")
    @ResponseBody
    public DggRestResponse subjectList(@RequestParam Map params) {
        try {
            List<Map<String, Object>> evaluatingPaperSubjects = evaluatingService.subjectListWithPage(params);
            return new DataTableResponse().data(params,evaluatingPaperSubjects);
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     * 选项列表
     * @param params
     * @return
     */
    @RequestMapping(value = "/options_list")
    @ResponseBody
    public DggRestResponse optionsList(@RequestParam Map params) {
        try {
            List<EvaluatingBasicOptions> evaluatingBasicOptionss = evaluatingService.optionsListWithPage(params);
            return new DataTableResponse().data(params,evaluatingBasicOptionss);
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     * 评估结果列表
     * @param params
     * @return
     */
    @RequestMapping(value = "/assessment_list")
    @ResponseBody
    public DggRestResponse assessmentList(@RequestParam Map params) {
        try {
            List<EvaluatingResults> evaluatingBasicOptionss = evaluatingService.assessmentListWithPage(params);
            return new DataTableResponse().data(params,evaluatingBasicOptionss);
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     * 新增评估结果级别
     */
    @RequestMapping(value = "/add_assessment_level")
    public String addAssessmentLevel(Long id, Model model) {
        if(id != null){
            EvaluatingRatingLevel evaluatingRatingLevel = evaluatingService.getRatingLevelById(id);
            model.addAttribute("evaluatingRatingLevel",evaluatingRatingLevel);
        }
        return "rzsc/evaluating/add_assessment_level";
    }

    /**
     * 评估结果级别列表
     * @param params
     * @return
     */
    @RequestMapping(value = "/assessment_level_list")
    @ResponseBody
    public DggRestResponse assessmentLevelList(@RequestParam Map params) {
        try {
            List<EvaluatingRatingLevel> evaluatingRatingLevels = evaluatingService.queryAssessmentLevelWithPage(params);
            return new DataTableResponse().data(params,evaluatingRatingLevels);
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }
    /**
     * 试题列表
     * @param params
     * @return
     */
    @RequestMapping(value = "/paper_list")
    @ResponseBody
    public DggRestResponse paperList(@RequestParam Map params) {
        try {
            List<EvaluatingTestPaper> evaluatingTestPapers = evaluatingService.paperListWithPage(params);
            return new DataTableResponse().data(params,evaluatingTestPapers);
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     *保存 渠道
     * @return
     */
    @RequestMapping(value = "/save_channel")
    @ResponseBody
    public DggRestResponse saveChannel(@ModelAttribute EvaluatingBaseChannel evaluatingBaseChannel) {
        try {
            DggValidateUtil.notNull(evaluatingBaseChannel,ProductOrderExcption.class,"对象为空");
            DggValidateUtil.notNull(evaluatingBaseChannel.getChannelName(),ProductOrderExcption.class,"名称为空");
            DggValidateUtil.notNull(evaluatingBaseChannel.getChannelCode(),ProductOrderExcption.class,"编号为空");

            //判断name重复
            Map channelNameMap = new HashMap();
            channelNameMap.put("channelName",evaluatingBaseChannel.getChannelName());
            channelNameMap.put("id",evaluatingBaseChannel.getId());
            int countChannelName = evaluatingService.countByParams(channelNameMap);
            if(countChannelName>0){
                return this.getFailResponse("名称重复");
            }
            //判断code重复
            Map channelCodeMap = new HashMap();
            channelCodeMap.put("channelCode",evaluatingBaseChannel.getChannelCode());
            channelCodeMap.put("id",evaluatingBaseChannel.getId());
            int countChannelCode = evaluatingService.countByParams(channelCodeMap);
            if(countChannelCode>0){
                return this.getFailResponse("编号重复");
            }
            evaluatingService.saveChannel(evaluatingBaseChannel);
            return this.getSuccessResponse("保存成功");
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }
    /**
     * 删除渠道
     * @return
     */
    @RequestMapping(value = "/delete_channel")
    @ResponseBody
    public DggRestResponse deleteChannel(Long id) {
        try {
            DggValidateUtil.notNull(id,ProductOrderExcption.class,"id为空");
            EvaluatingBaseChannel evaluatingBaseChannel = new EvaluatingBaseChannel();
            evaluatingBaseChannel.setId(id);
            evaluatingBaseChannel.setFlag(1);
            evaluatingService.saveChannel(evaluatingBaseChannel);
            return this.getSuccessResponse("删除成功");
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }
    /**
     *保存选项
     * @return
     */
    @RequestMapping(value = "/save_options")
    @ResponseBody
    public DggRestResponse saveOptions(@ModelAttribute EvaluatingBasicOptions evaluatingBasicOptions) {
        try {
            DggValidateUtil.notNull(evaluatingBasicOptions,ProductOrderExcption.class,"对象为空");
            DggValidateUtil.notNull(evaluatingBasicOptions.getOptionsName(),ProductOrderExcption.class,"名称为空");
            DggValidateUtil.notNull(evaluatingBasicOptions.getOptionsCode(),ProductOrderExcption.class,"编号为空");
            evaluatingService.saveOptions(evaluatingBasicOptions);
            return this.getSuccessResponse("保存成功");
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     * 删除选项
     * @return
     */
    @RequestMapping(value = "/delete_options")
    @ResponseBody
    public DggRestResponse deleteOptions(Long id) {
        try {
            DggValidateUtil.notNull(id,ProductOrderExcption.class,"id为空");
            EvaluatingBasicOptions evaluatingBasicOptions = new EvaluatingBasicOptions();
            evaluatingBasicOptions.setId(id);
            evaluatingBasicOptions.setFlag(1);
            evaluatingService.saveOptions(evaluatingBasicOptions);
            return this.getSuccessResponse("删除成功");
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     *保存评估结果
     * @return
     */
    @RequestMapping(value = "/save_assessment")
    @ResponseBody
    public DggRestResponse saveOptions(@ModelAttribute EvaluatingResults evaluatingResults) {
        try {
            DggValidateUtil.notNull(evaluatingResults,ProductOrderExcption.class,"对象为空");
            DggValidateUtil.notNull(evaluatingResults.getResultsName(),ProductOrderExcption.class,"评估结果名称为空");
            DggValidateUtil.notNull(evaluatingResults.getPaperId(),ProductOrderExcption.class,"匹配试题为空");

            //判断name重复
            Map assessmentNameMap = new HashMap();
            assessmentNameMap.put("resultsName",evaluatingResults.getResultsName());
            assessmentNameMap.put("id",evaluatingResults.getId());
            int countOptionsName = evaluatingService.countAssessmentByParams(assessmentNameMap);
            if(countOptionsName>0){
                return this.getFailResponse("名称重复");
            }
            evaluatingService.saveAssessment(evaluatingResults);
            return this.getSuccessResponse("保存成功");
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     *保存 试题
     * @return
     */
    @RequestMapping(value = "/save_paper")
    @ResponseBody
    public DggRestResponse savePaper(@ModelAttribute EvaluatingTestPaper evaluatingTestPaper) {
        try {
            DggValidateUtil.notNull(evaluatingTestPaper,ProductOrderExcption.class,"对象为空");
            DggValidateUtil.notNull(evaluatingTestPaper.getPaperName(),ProductOrderExcption.class,"名称为空");
            DggValidateUtil.notNull(evaluatingTestPaper.getPaperCode(),ProductOrderExcption.class,"编号为空");

            //判断name重复
            Map paperNameMap = new HashMap();
            paperNameMap.put("paperName",evaluatingTestPaper.getPaperName());
            paperNameMap.put("id",evaluatingTestPaper.getId());
            int countPaperName = evaluatingService.countPaperByParams(paperNameMap);
            if(countPaperName>0){
                return this.getFailResponse("名称重复");
            }
            //判断code重复
            Map paperCodeMap = new HashMap();
            paperCodeMap.put("paperCode",evaluatingTestPaper.getPaperCode());
            paperCodeMap.put("id",evaluatingTestPaper.getId());
            int countPaperCode = evaluatingService.countPaperByParams(paperCodeMap);
            if(countPaperCode>0){
                return this.getFailResponse("编号重复");
            }
            evaluatingService.savePaper(evaluatingTestPaper);
            return this.getSuccessResponse("保存成功");
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     * 删除试题
     * @return
     */
    @RequestMapping(value = "/delete_paper")
    @ResponseBody
    public DggRestResponse deletePaper(Long id) {
        try {
            DggValidateUtil.notNull(id,ProductOrderExcption.class,"id为空");
            EvaluatingTestPaper evaluatingTestPaper = new EvaluatingTestPaper();
            evaluatingTestPaper.setId(id);
            evaluatingTestPaper.setFlag(1);
            evaluatingService.savePaper(evaluatingTestPaper);
            return this.getSuccessResponse("删除成功");
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     * 查询渠道和选项关联的渠道
     * @param optionsId  选项id
     * @return
     */
    @RequestMapping(value = "/query_channel_list")
    @ResponseBody
    public DggRestResponse queryChannelList(Long optionsId) {
        try {
            DggValidateUtil.notNull(optionsId,ProductOrderExcption.class,"选项id为空");
            Map params = new HashMap();
            //查询所有渠道
            List<EvaluatingBaseChannel> evaluatingBaseChannels = evaluatingService.channelListWithPage(params);
            params.put("evaluatingBaseChannels",evaluatingBaseChannels);
            //查询选项所关联的渠道
            List<EvaluatingOptionsChannel> evaluatingOptionsChannels = evaluatingService.findChannelByOptionsId(optionsId);
            params.put("evaluatingOptionsChannels",evaluatingOptionsChannels);
            return this.getSuccessResponse(params);
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }


    /**
     *保存 选项关联渠道
     * @return
     */
    @RequestMapping(value = "/save_options_channel")
    @ResponseBody
    public DggRestResponse saveOptionsChannel(@RequestBody EvaluatingOptionsChannelDto evaluatingOptionsChannelDto) {
        try {
            DggValidateUtil.notNull(evaluatingOptionsChannelDto,ProductOrderExcption.class,"对象为空");
            DggValidateUtil.notNull(evaluatingOptionsChannelDto.getOptionsId(),ProductOrderExcption.class,"选项id为空");
            evaluatingService.saveOptionsChannel(evaluatingOptionsChannelDto);
            return this.getSuccessResponse("保存成功");
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     * 编辑题目
     */
    @RequestMapping(value = "/edit_paper_subject")
    public String editPaperSubject(Long paperId, Model model) {
        //根据试题id查询题目
        Map params = new HashMap();
        params.put("paperId",paperId);
        List<SubjectOptionsDto> evaluatingPaperSubjects = evaluatingService.queryPaperSubject();
        List<SubjectOptionsDto> subjectOptionsDtos = evaluatingService.queryPaperSubjectByPaperId(params);
        model.addAttribute("paperId",paperId);
        model.addAttribute("evaluatingPaperSubjects",evaluatingPaperSubjects);
        model.addAttribute("subjectOptionsDtos",subjectOptionsDtos);
        return "rzsc/evaluating/edit_paper_subject";
    }



    /**
     *保存基础题目
     * @return
     */
    @RequestMapping(value = "/save_subject")
    @ResponseBody
    public DggRestResponse saveSubject(@ModelAttribute EvaluatingPaperSubject evaluatingPaperSubject) {
        try {
            DggValidateUtil.notNull(evaluatingPaperSubject,ProductOrderExcption.class,"对象为空");
            DggValidateUtil.notNull(evaluatingPaperSubject.getSubjectName(),ProductOrderExcption.class,"名称为空");
            DggValidateUtil.notNull(evaluatingPaperSubject.getPaperId(),ProductOrderExcption.class,"所属题目为空");
            evaluatingService.saveSubject(evaluatingPaperSubject);
            return this.getSuccessResponse("保存成功");
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     * 编辑客户级别-显示数据列表
     */
    @RequestMapping(value = "/rating_level_list")
    public String ratingLevelList(Long resultsId, Model model) {
        //根据结果id查询客户级别
        List<EvaluatingRatingLevel> matchedLevels = evaluatingService.queryRatingLevelByAssessmentId(resultsId, 1);
        List<EvaluatingRatingLevel> noMatchedLevels = evaluatingService.queryRatingLevelByAssessmentId(resultsId, 2);
        model.addAttribute("resultsId",resultsId);
        model.addAttribute("matchedLevels",matchedLevels);
        model.addAttribute("noMatchedLevels",noMatchedLevels);
        return "rzsc/evaluating/rating_level_list";
    }

    /**
     * 基础题目-关联选项
     */
    @RequestMapping(value = "/base_options_list")
    public String optionsList(Long subjectId, Model model) {
        //根据结果id查询客户级别
        List<EvaluatingBasicOptions> matchedOptions = evaluatingService.queryOptionsBySubjectId(subjectId, 1);
        List<EvaluatingBasicOptions> noMatchedOptions = evaluatingService.queryOptionsBySubjectId(subjectId, 2);
        model.addAttribute("subjectId",subjectId);
        model.addAttribute("matchedOptions",matchedOptions);
        model.addAttribute("noMatchedOptions",noMatchedOptions);
        return "rzsc/evaluating/base_options_list";
    }

    /**
     * 编辑客户级别绑定
     */
    @RequestMapping(value = "/edit_rating_level_binding")
    @ResponseBody
    public DggRestResponse editRatingLevelBinding(Long resultsId, Long levelId,Integer handleType) {
        try {
            DggValidateUtil.notNull(resultsId, ProductOrderExcption.class,"结果不能为空");
            DggValidateUtil.notNull(levelId, ProductOrderExcption.class,"客户级别不能为空");
            DggValidateUtil.notNull(handleType, ProductOrderExcption.class,"操作类型不能为空");
            String msg = "解除绑定客户级别成功";
            if(handleType == 2){
                msg = "绑定客户级别成功";
            }
            evaluatingService.editRatingLevelBinding(resultsId, levelId, handleType);
            return this.getSuccessResponse(msg);
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     * 编辑选项绑定
     */
    @RequestMapping(value = "/edit_option_binding")
    @ResponseBody
    public DggRestResponse editOptionBinding(Long subjectId, Long optionId,Integer handleType) {
        try {
            DggValidateUtil.notNull(subjectId, ProductOrderExcption.class,"题目不能为空");
            DggValidateUtil.notNull(optionId, ProductOrderExcption.class,"选项不能为空");
            DggValidateUtil.notNull(handleType, ProductOrderExcption.class,"操作类型不能为空");
            String msg = "解除绑定选项成功";
            if(handleType == 2){
                msg = "绑定选项成功";
            }
            evaluatingService.editOptionBinding(subjectId, optionId, handleType);
            return this.getSuccessResponse(msg);
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     *保存 试题题目
     * @return
     */
    @RequestMapping(value = "/save_paper_subject")
    @ResponseBody
    public DggRestResponse savePaperSubject(@RequestBody EvaluatingPaperSubjectDto evaluatingPaperSubjectDto) {
        try {
            DggValidateUtil.notNull(evaluatingPaperSubjectDto,ProductOrderExcption.class,"对象为空");
            DggValidateUtil.notNull(evaluatingPaperSubjectDto.getPaperId(),ProductOrderExcption.class,"试题id为空");
            evaluatingService.savePaperSubject(evaluatingPaperSubjectDto);
            return this.getSuccessResponse("保存成功");
        }catch (ProductOrderExcption e){
            logger.error("/save_paper_subject",e,evaluatingPaperSubjectDto);
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            logger.error("/save_paper_subject",e,evaluatingPaperSubjectDto);
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }



    /**
     *保存 客户级别
     * @return
     */
    @RequestMapping(value = "/save_rating_level")
    @ResponseBody
    public DggRestResponse saveRatingLevel(@ModelAttribute EvaluatingRatingLevel evaluatingRatingLevel) {
        try {
            DggValidateUtil.notNull(evaluatingRatingLevel,ProductOrderExcption.class,"对象为空");
            DggValidateUtil.notNull(evaluatingRatingLevel.getLevel(),ProductOrderExcption.class,"级别为空");
            evaluatingService.saveRatingLevel(evaluatingRatingLevel);
            return this.getSuccessResponse("保存成功");
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     * 删除题目
     * @return
     */
    @RequestMapping(value = "/delete_assessment_level")
    @ResponseBody
    public DggRestResponse deleteAssessmentLevel(Long id) {
        try {
            DggValidateUtil.notNull(id,ProductOrderExcption.class,"id为空");
            EvaluatingRatingLevel evaluatingRatingLevel = new EvaluatingRatingLevel();
            evaluatingRatingLevel.setId(id);
            evaluatingRatingLevel.setFlag(1);
            evaluatingService.saveRatingLevel(evaluatingRatingLevel);
            return this.getSuccessResponse("删除成功");
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     * 编辑渠道字段
     */
    @RequestMapping(value = "/edit_channel_field")
    public String editChannelField(Long channelId,String channelCode,Integer fieldType, Model model) {
        //根据渠道id查询题目
        Map params = new HashMap();
        params.put("channelId",channelId);
        params.put("fieldType",fieldType);
        List<EvaluatingChannelField> evaluatingChannelFields = evaluatingService.queryChannelFieldByChannelId(params);
        model.addAttribute("channelId",channelId);
        model.addAttribute("channelCode",channelCode);
        model.addAttribute("fieldType",fieldType);
        model.addAttribute("evaluatingChannelFields",evaluatingChannelFields);
        return "rzsc/evaluating/edit_channel_field";
    }

    /**
     *保存 渠道字段
     * @return
     */
    @RequestMapping(value = "/save_channel_field")
    @ResponseBody
    public DggRestResponse saveChannelField(@RequestBody EvaluatingChannelFieldDto evaluatingChannelFieldDto) {
        try {
            DggValidateUtil.notNull(evaluatingChannelFieldDto,ProductOrderExcption.class,"对象为空");
            evaluatingService.saveChannelField(evaluatingChannelFieldDto);
            return this.getSuccessResponse("保存成功");
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }



    /**
     * 导入 试题
     * @return
     */
    @RequestMapping(value = "/import_excel")
    @ResponseBody
    public DggRestResponse importExcel(@RequestParam MultipartFile excelFile) {
        try {
            DggValidateUtil.notNull(excelFile.getName(),ProductOrderExcption.class,"文件为空");
            List<Map> mapList = ReadExcel.readXls(excelFile.getInputStream(),excelFile.getOriginalFilename());
            evaluatingService.importExcel(mapList);
            return this.getSuccessResponse("读取成功");
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }
}
